package MyOs;

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        ProcessManager pm = new ProcessManager();
        PcbQueue pc=new PcbQueue();
        while (true) {
            System.out.println("请输入一个进程的name和time(按N表示结束进程的初始化)：");
            String name = reader.next();
            if (name.equals("N")) {
                break;
            }
            int time = reader.nextInt();
            while (time < 0) {//检车初始化时间错误
                System.out.println("初始化的进程时间不符合要求，请重新初始化");
                time = reader.nextInt();
            }
            Pcb pb = pm.createProcess(name, time);
            System.out.println("请为该进程初始化运行状态(running,ready,waiting)：");
            String info = reader.next();
            while (!info.equals("running") && !info.equals("waiting") && !info.equals("ready")) {//状态差错检查
                System.out.println("初始化状态不符合要求");
                System.out.println("请为该进程初始化运行状态(running,ready,waiting)：");
                info = reader.next();
            }
            switch (info) {
                case "running":
                    pc.add2Running(pb);
                    break;
                case "ready":
                    pc.add2Ready(pb);
                    break;
                case "waiting":
                    pc.add2Waiting(pb);
                    break;
                default:
                    break;
            }
           // System.out.println(pb.getPid() + " " + pb.getName() + " " + pb.getRemainTime() + " " + pb.getStatus());
        }
        System.out.println("是否要进行删除操作(Y表示删除，N表示不删除：");
        String num = reader.next();
        int pNum = 0;
        while (!num.equals("Y") && !num.equals("N")) {
            System.out.println("操作指令输入错误");
            System.out.println("是否要进行删除操作(Y表示删除，N表示不删除：");
            num = reader.next();
        }
        if (num.equals("Y")) {
            System.out.println("请输入要删除的进程的pid：");
            pNum = reader.nextInt();
            pm.destroyProcess(pNum);
        }
        new ClockInterrupt();
    }
}
